package com.example.sen.jxdemo;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.os.Process;
import android.util.Log;

import com.jxccp.im.chat.manager.JXImManager;
import com.jxccp.ui.JXUiHelper;
import com.xiaomi.mipush.sdk.MiPushClient;

import java.util.List;

/**
 * Created by Sen on 2017/4/20.
 */
public class DemoApplication extends Application {

    static final String TAG = "DemoApplication";

    public static final String MI_PUSH_APP_ID = "2882303761517745253";
    public static final String MI_PUSH_APP_KEY = "5931774572253";
    public static final String MI_PUSH_TAG = "com.example.sen.jxdemo";

    @Override
    public void onCreate() {
        super.onCreate();
        if(shouldInit()) {
            //示例集成小米推送
            MiPushClient.registerPush(this, MI_PUSH_APP_ID, MI_PUSH_APP_KEY);
        }
        // 初始化SDK
        Log.w(TAG, "DemoApplication oncreate, " + getApplicationContext());
        JXImManager.getInstance().init(getApplicationContext(), "cgkzoddudxh2zg#bear079#10001");
        JXImManager.getInstance().setDebugMode(true);
    }


    private boolean shouldInit() {
        ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
        List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
        String mainProcessName = getPackageName();
        int myPid = Process.myPid();
        for (ActivityManager.RunningAppProcessInfo info : processInfos) {
            if (info.pid == myPid && mainProcessName.equals(info.processName)) {
                return true;
            }
        }
        return false;
    }

}
